<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>商品列表</h2>
	</div>
	<div class="cf">
		<div class="fl">
            <a class="btn" href="{:U('add')}">新 增</a>
            <button class="btn ajax-post" url="{:U('setStatus',array('status'=>1,'model'=>'goods'))}" target-form="ids">上 架</button>
            <button class="btn ajax-post" url="{:U('setStatus',array('status'=>2,'model'=>'goods'))}" target-form="ids">下 架</button>
        </div>

        <!-- 高级搜索 -->
		<div class="search-form fr cf">
			<div class="sleft">
				<input type="text" name="name" class="search-input" value="{:I('name')}" placeholder="请输入商品名称或者ID">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('showlist')}"><i class="btn-search"></i></a>
			</div>
		</div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
	<table class="">
    <thead>
        <tr>
        		<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
        		<th class="">ID</th>
        		<th class="">所属分类</th>
        		<th class="">图片</th>
        		<th class="">商品名</th>
        		<th class="">型号</th>
        		<th class="">价格</th>
        		<th class="">销量</th>
        		<th class="">状态</th>
        		<th class="">添加时间</th>
        		<th class="">操作</th>
    		</tr>
    </thead>
    <tbody>
		<notempty name="data">
		<foreach name="data" item="vo">
		<tr class="trr">
      <td><input class="ids" type="checkbox" name="ids[]" value="{$vo.goods_id}" /></td>
			<td>{$vo.goods_id} </td>
			<td>{$vo.classify_id}</td>
			<td><img src="./Uploads{$vo.img_path}" width="60px;" alt=""></td>
			<td>{$vo.goodsname}</td>
			<td>{$vo.number}</td>
			<td>{$vo.price}</td>
			<td>{$vo.sale}</td>
			<td>{$vo.status}</td>
			<td>{$vo.addtime|date="Y/m/d",###}</td>
			<td><eq name="vo.status" value="1">
				<a href="{:U('User/changeStatus?method=forbidUser&id='.$vo['uid'])}" class="ajax-get">禁用</a>
				<else/>

				<a href="{:U('details?id='.$vo['goods_id'])}"  >查看详情</a>
				</eq>

				<!-- <a href='#'  class="authorize"  sta='{$vo.status}' goodsid ='{$vo.goods_id}' >上架</a> -->
				<a href="{:U('img?goods_id='.$vo['goods_id'])}" class="img"  sta='{$vo.status}' goodsid ='{$vo.goods_id}' >查看图片</a>
      </td>
		</tr>
		</foreach>
		<else/>
		<td colspan="9" class="text-center"> aOh! 暂时还没有内容! </td>
		</notempty>
	</tbody>
    </table>
	</div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    //导航高亮
    highlight_subnav('{:U('Goods/showlist')}');

    //JS 同补上下架
    $('.authorize').each(function(){
    	var sta = $(this).attr('sta');
    	if (sta == '新发布') {
    		$(this).html('上架');
    	}else if(sta == '上架'){
    		$(this).html('下架');
    	}else{
    		$(this).html('上架');
    	}

	});


    // 上架的操作
    $('.authorize').click(function()
	{

		var status = $(this).attr('sta');

		var goods_id = $(this).attr('goodsid');
		$.get('{:U("Goods/up")}' , {status : status , goods_id : goods_id} , function(data)
		{
			console.log(data);
		});

		var sta = $(this).attr('sta');
    	
    	if (sta == '新发布') {
    		$(this).attr('sta' , '上架')
    		$(this).html('下架');
    		$(this).parent().prev().prev().html('上架');

    	}
    	if (sta == '上架'){
    		$(this).attr('sta' ,'下架')
    		$(this).html('上架');
    		$(this).parent().prev().prev().html('下架');
    	}
    	if (sta == '下架'){
    		$(this).attr('sta' ,'上架')
    		$(this).html('下架');
    		$(this).parent().prev().prev().html('上架');
    	}

	});
	</script>
</block>
